package com.yingran.common;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

public class NoticeDialog extends BaseDialog {

    private TextView dialog_tip;
    private View dialog_cancel;
    private View dialog_enter;
    private String tipMsg;
    private EnterClickListener enterClickListener;
    private CancelClickListener cancelClickListener;

    @Override
    public void show() {
        super.show();
        Window window = getWindow();
        if (window == null) {
            return;
        }
        WindowManager.LayoutParams lp = window.getAttributes();
        window.setGravity(Gravity.CENTER);
        lp.width = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
    }

    public NoticeDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.common_layout_dialog_notice);
        dialog_tip = findViewById(R.id.dialog_tip);
        dialog_tip.setText(tipMsg);
        dialog_cancel = findViewById(R.id.dialog_cancel);
        dialog_enter = findViewById(R.id.dialog_enter);
        dialog_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (cancelClickListener != null) {
                    cancelClickListener.cancel(NoticeDialog.this);
                }
            }
        });
        dialog_enter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (enterClickListener != null) {
                    enterClickListener.enter(NoticeDialog.this);
                }
            }
        });
    }

    public NoticeDialog setMsg(String tipMsg) {
        this.tipMsg = tipMsg;
        if (dialog_tip != null) {
            dialog_tip.setText(tipMsg);
        }
        return this;
    }

    public NoticeDialog setEnterClickListener(EnterClickListener enterClickListener) {
        this.enterClickListener = enterClickListener;
        return this;
    }

    public NoticeDialog setCancelClickListener(CancelClickListener cancelClickListener) {
        this.cancelClickListener = cancelClickListener;
        return this;
    }

    public interface EnterClickListener {
        void enter(BaseDialog dialog);
    }

    public interface CancelClickListener {
        void cancel(BaseDialog dialog);
    }
}
